package servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import biz.AddressBiz;
import biz.CustomerBiz;
import biz.impl.AddressBizImpl;
import biz.impl.CustomerBizImpl;
import entity.Address;
import entity.Customer;
import entity.Street;

/**
 * Servlet implementation class EditAddressServlet
 */
@WebServlet("/EditAddress")
public class EditAddressServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String cusStr = request.getParameter("cusId");
		String streetStr = request.getParameter("street");
		String address = request.getParameter("address");
		int cus=0;
		int street=0;
		if(cusStr!=null && !cusStr.isEmpty()){
			cus=Integer.valueOf(cusStr);
		}
		if(streetStr!=null&&!streetStr.isEmpty()){
			street=Integer.valueOf(streetStr);
		}
		AddressBiz addressBiz = new AddressBizImpl();
		Address addr = new Address();
		addr.setDetailAddress(address);
		Customer customer = new Customer();
		customer.setCusId(cus);
		addr.setCustomer(customer);
		addr.setStreet(new Street(street, null, null));
		
		addressBiz.addAddress(addr);
		
		CustomerBiz biz = new CustomerBizImpl();
		Customer cust=biz.queryCustomerInfo(cus);
		request.getSession().setAttribute("user", cust);
		response.sendRedirect(request.getContextPath()+"/MyCenter.html");
	}
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
